//
//  WMComNewsTable.m
//  witMorning
//
//  Created by Mac mini on 2018/1/2.
//  Copyright © 2018年 zt. All rights reserved.
//

#import "WMComNewsTable.h"
#import "WMComCell.h"
#import "NPHomeHeaderBar.h"
#import "WMNewsViewController.h"
@implementation WMComNewsTable
{
    NPHomeHeaderBar *bar;
}
-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    [self reloadData];
}


-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    if (self = [super initWithFrame:frame style:style]) {
        
        UINib *nib = [UINib nibWithNibName:@"WMComCell" bundle:nil];
        [self registerNib:nib forCellReuseIdentifier:identifier];
        
        self.delegate =self;
        self.dataSource = self;
        
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray ? _dataArray.count : 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return .1;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, .1)];
    return view;
}

static NSString *identifier = @"CELL";

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
   
    WMComCell *cell = [self dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[WMComCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    cell.title.text = _dataArray[indexPath.row][@"doc_subject"];
    cell.time.text = _dataArray[indexPath.row][@"doc_create_time"];
    
    return cell;
//    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 18, 4, 4)];
//    lab.backgroundColor = [UIColor blackColor];
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    WMNewsViewController *news = [[WMNewsViewController alloc]init];
    news.textStr = _dataArray[indexPath.row][@"doc_content"];
    [self.controller.navigationController pushViewController:news animated:YES];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
